<?php
namespace app\admin\controller;


use think\Request;
use think\Controller;
use View;
use Db;
use Session;
use app\common\model\User as UserModel;
use app\admin\validate\AddUser;

class User extends Controller
{



    public function userlist(UserModel $userModel){

        $datas = $userModel->getPageList();

        $this->assign('datas', $datas);

        return $this->fetch();
    }

    public function adduser(){

        return $this->fetch();
    }

    public function adduserDo(Request $request, UserModel $userModel){
        $param = $request->param();
        $validate= new AddUser();
        try{
            $result = $validate->checkDo($param);
        }catch (Exception $e){
            return $this->error($e->getMessage());
        }

        if (!$result) {
            return $this->error($validate->getError());
        }


        if($userModel->addUser($param)){


            return $this->success('添加成功', url('/admin/user/userlist'));
        }


        return $this->error('添加失败');


    }

}